package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.Performance;
import cn.classyex.business.hr.service.IPerformanceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 绩效管理Controller
 * 
 * @author yex
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/hr/performance")
public class PerformanceController extends BaseController
{
    private String prefix = "hr/performance";

    @Autowired
    private IPerformanceService performanceService;

    @RequiresPermissions("hr:performance:view")
    @GetMapping()
    public String performance()
    {
        return prefix + "/performance";
    }

    /**
     * 查询绩效管理列表
     */
    @RequiresPermissions("hr:performance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Performance performance)
    {
        startPage();
        List<Performance> list = performanceService.selectPerformanceList(performance);
        return getDataTable(list);
    }

    /**
     * 导出绩效管理列表
     */
    @RequiresPermissions("hr:performance:export")
    @Log(title = "绩效管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Performance performance)
    {
        List<Performance> list = performanceService.selectPerformanceList(performance);
        ExcelUtil<Performance> util = new ExcelUtil<Performance>(Performance.class);
        return util.exportExcel(list, "绩效管理数据");
    }

    /**
     * 新增绩效管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存绩效管理
     */
    @RequiresPermissions("hr:performance:add")
    @Log(title = "绩效管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Performance performance)
    {
        return toAjax(performanceService.insertPerformance(performance));
    }

    /**
     * 修改绩效管理
     */
    @GetMapping("/edit/{performanceId}")
    public String edit(@PathVariable("performanceId") Long performanceId, ModelMap mmap)
    {
        Performance performance = performanceService.selectPerformanceById(performanceId);
        mmap.put("performance", performance);
        return prefix + "/edit";
    }

    /**
     * 修改保存绩效管理
     */
    @RequiresPermissions("hr:performance:edit")
    @Log(title = "绩效管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Performance performance)
    {
        return toAjax(performanceService.updatePerformance(performance));
    }

    /**
     * 删除绩效管理
     */
    @RequiresPermissions("hr:performance:remove")
    @Log(title = "绩效管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(performanceService.deletePerformanceByIds(ids));
    }
}
